<template>
  <router-view v-slot="{ Component }">
    <component :is="Component" />
  </router-view>
</template>
<script>
import { defineComponent, provide, onMounted } from 'vue';
import { ElConfigProvider } from 'element-plus'
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
import { getPersonInfo } from '@/server/home'
import { useRequest } from 'vue-hooks-plus';
import { useStore } from 'vuex';

export default defineComponent({
  components: {
    ElConfigProvider,
  },
  setup () {
    const store = useStore()
    const { runAsync: refreshUserInfo } = useRequest(getPersonInfo, {
      onSuccess: res => {
        window.localStorage.setItem('userId', res.userId)
        store.commit('saveInfo', res)
        store.dispatch('checkApplyList')
        store.dispatch('getFriendByType', { index: 0 })
        store.dispatch('getFriendByType', { index: 3 })
      },
      manual: true
    })
    provide('refreshUserInfo', refreshUserInfo)
    onMounted(() => {
      refreshUserInfo()
    })
    return {
      locale: zhCn,
    }
  },
})
</script>
